// TOWN SCRIPT
//    Town 2

// This is the special encounter script for this town.
// The states INIT_STATE, EXIT_STATE, and START_STATE have
// meanings that are described in the documenation. States you write
// yourself should be numbered from 10-100.

begintownscript;

variables;

body;

beginstate INIT_STATE;
// Called upon entering
break;

beginstate EXIT_STATE;
// Always called when the town is left.
break;

beginstate START_STATE;
// Called every turn.
break;

//Stop them going back to previous town
beginstate 10;
	message_dialog("Whilst heading back may be tempting, you wouldn't be able to get very far - the gates that block your way are operated from the other side. You have no choice but to press on.","");
	block_entry(1);
break;

//Moving north
beginstate 11;
	message_dialog("You cautiously creep north trying not to make too much noise - the last thing you need now is to fight that monster again.","");
	move_to_new_town(3,24,39);
break;

//Just entering cave
beginstate 12;
	if(get_flag(2,0) == 0) {
		reset_dialog();
		add_dialog_str(0,"You enter this network of caves warily, alert to any potential danger - whoever slammed the gates behind you before could be lying in wait ahead, ready to take advantage of your weakened state.",0);
		add_dialog_str(1,"However, the caves ahead are as silent as the ones you have just left. Whilst there might be somebody, or something, up ahead, you're in no danger right now.",0);
		add_dialog_str(2,"Nevertheless, you keep your hand close to your weapons, just in case.",0);
		run_dialog(1);
		set_flag(2,0,1);
	}
break;

//Swamp again
beginstate 13;
	if(get_flag(2,1) == 0) {
		message_dialog("Up ahead is a small swamp - the caverns here must be particularly damp - and, just beyond it, you can make out a large patch of alchemical herbs; even from here you can see that they are ripe and ready to pick.","However, the floor to reach them is particularly treacherous - you should probably proceed with care, lest you get bogged down.");
		set_flag(2,1,1);
	}
break;

//Shrooms, SW
beginstate 14;
	if(get_flag(2,2) == 0) {
		if(get_skill_total(14) < 5) {
			message_dialog("You take a look at the plants growing here and spot two bunches of herbs that you know are useful for making energetic potions.","You carefully take them, being careful not to damage them, and pack them away. Unfortunately nothing else in the patch of plants looks useful.");
			set_flag(2,2,1);
			reward_give(216);
			reward_give(216);
			end();
		}
		if(get_skill_total(14) < 10) {
			message_dialog("You take a look at the plants growing here and spot three bunches of herbs that you know are useful for making energetic potions.","You carefully take them, being careful not to damage them, and pack them away. Unfortunately nothing else in the patch of plants looks useful.");
			set_flag(2,2,1);
			reward_give(216);
			reward_give(216);
			reward_give(216);
			end();
		}
		if(get_skill_total(14) > 10) {
			message_dialog("You take a look at the plants growing here and spot three bunches of herbs that you know are useful for making energetic potions, and some mandrake.","You carefully take them, being careful not to damage them, and pack them away. Unfortunately nothing else in the patch of plants looks useful.");
			set_flag(2,2,1);
			reward_give(216);
			reward_give(216);
			reward_give(216);
			reward_give(219);
			end();
		}
	} else {
		message_dialog("You've already searched this patch of herbs and mushrooms - there is nothing else here that looks useful to you.","");
		end();
	}
break;

//Big rock fall.
beginstate 15;
	if(get_flag(2,3) == 0) {
		message_dialog("A huge rockfall has blocked the passage-way ahead - it looks as though a large cavequake has shaken loose a large amount of rubble, rendering the route impassable.","If you wanted to explore the other side, you'd have to find another way around.");
		set_flag(2,3,1);
	} else {
		message_dialog("This passage is still blocked - you'll have to find another way around.","");
	}
break;

//More Shrooms, (SE)
beginstate 16;
	if(get_flag(2,4) == 0) {
		message_dialog("You examine this small patch of mushrooms closely, but there are no useful reagents growing here.","You move on.");
		set_flag(2,4,1);
	}
break;

//Coughing, hurt them!
beginstate 17;
	if(get_flag(2,5) == 0) {
		reset_dialog();
		add_dialog_str(0,"As you're walking down this tunnel you suddenly double over in intense pain, before collapsing into a fit of coughing.",0);
		add_dialog_str(1,"After a moment of agony you wipe your mouth, trailing blood onto your hand - clearly, when you fell you did more damage to yourself than you first thought.",0);
		add_dialog_str(2,"You get to your feet, steadying yourself on the cave wall behind you. You should really try to find somewhere with healers sooner rather than later...",0);
		run_dialog(1);
		set_flag(2,5,1);
		damage_char(1000,25,4);
	}
break;

//OH NO RAWR
beginstate 18;
	if(get_flag(2,6) == 0) {
		message_dialog("You round this corner and stop dead - a dread howling exactly the same as the one you heard before echoes through the caves. Whatever made it is much closer than before.","You grip your weapon tightly, but the caves remain silent. Still, it would probably be wise to continue cautiously.");
		set_flag(2,6,1);
	}
break;

//Exit to west.
beginstate 19;
	message_dialog("Another cavequake has cut off this cave - you won't be able to leave this way.","");
	block_entry(1);
break;

//Another block
beginstate 20;
	if(get_flag(2,10) == 0) {
		message_dialog("The cavern here has been blocked by an impassable wall of rubble and rock. You won't be able to pass this way.","");
		set_flag(2,10,1);
	}
break;

//Monster!!
beginstate 21;
	if(get_flag(2,8) == 0) {
		message_dialog("As you enter this small chamber, you hear a huge snarl from the south. As you grab your weapons, you see a flash of red before you as a huge beast leaps forward and charges at you.","The thing is enormous; you've never seen anything like it. And, right now, it's trying to tear you limb from limb...");
		activate_hidden_group(1);
		set_flag(2,8,1);
	}
break;


//Stop them fleeing!
beginstate 22;
	if(get_flag(2,9) != 1) {
		message_dialog("You try to flee from the beast, but it snarls and leaps forward to strike you. You mange to evade it's blow, but you won't be able to leave whilst it's still here.","");
		block_entry(1);
	}
break;


	
